function run_qhformat(ed) {
	var nodes = ed.document.lastChild.childNodes[1].childNodes;
	var out = '';
	for ( var k in nodes) {
		if (typeof (nodes[k]) == 'undefined' || typeof (nodes[k]) != 'object')
			continue;

		var str = nodes[k].innerHTML;
		if (!str || str == '' || str == '<br>' || str == '<br />')
			continue;
		str = str.replace(/\[qh\]/g, '');
		str = str.replace(/\<BR\>/g, '<br>');
		var strd = str.split('<br>');
		var _s = '';
		for ( var x in strd) {
			if (strd[x] == '')
				continue;
			_s += strd[x] + '[qh]<br>';
		}

		str = _s;

		if (str.indexOf('[qh]') < 0) {
			str += '[qh]';
		}
		
		out += '<p>' + str + '</p>';
	}
	return out;
};
baidu.editor.plugins['QHFormat'] = function() {
	var me = this;

	me.addListener('keydown', function(type, evt) {
		var e = evt || window.event;
		var keycode = e.which ? e.which : e.keyCode;
		if (keycode == 119) {// && e.ctrlKey
			var str = run_qhformat(me.selection.getRange());
			me.setContent(str);
		}
	});
};

baidu.editor.ui.QHFormat = function(editor, title) {
	title = 'qh format';
	var ui = new baidu.editor.ui.Button({
		className : 'edui-for-qhformat',
		title : title,
		onclick : function() {
			var str = run_qhformat(editor);
			editor.setContent(str);
		}
	});

	return ui;
};